<!DOCTYPE html>
<html lang="en">
<head>
    <title>管理系统 - 管理中心</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- <meta ng-include="'head.html'"> -->
    <style type="text/css">
        
        .titleHead { font-family: 宋体; font-size: 14px; font-weight: 400; 
            margin-left: 5px; margin-bottom:15px; }
        ul>li>a{ cursor: pointer;}
        td>button{ border-radius: 5px!important; font-size: 12px!important }
    </style>
    <link rel="stylesheet" type="text/css" href="../lib/css/footable.bootstrap.min.css">
    <script src="../lib/js/jquery.min.js" type="text/javascript"></script>
    <script src="../js/build.js" type="text/javascript"></script>
    <script src="../js/public.js" type="text/javascript"></script>
</head>
<body class="flat-blue">
<div class="app-container H100" ng-app="myApp" ng-controller="myCtrl">
<div class="row content-container H100">
<div ng-include="'menus.html'" onload="loadReady()"></div>
<div class="container-fluid H100 pb15">
<div class="side-body padding-top H100" id="main" style="padding-top:65px">
    <!------------------Main---------------->
    <div class="H100" style="width:99%; background-color:#fff; position:relative">
        <div class="titleHead">➢数据池</div>
        <div style="position:absoluate; bottom:40px">
            <table class="table table-striped" style="padding-bottom: 20px"></table>
        </div>
    </div>
    <!------------------End Main---------------------->
</div>  <!--End side-body-->
</div>  <!--End container-fluid-->
</div>  <!--End content-container-->
<div ng-include="'footer.html'"></div>
</div>  <!--End app-container-->

<script type="text/javascript" src="../lib/js/footable.min.js"></script>
<script language="javascript">
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        loadCtlBase($scope);
        $scope.hideCols = { 'province':1, 'city':1, 'project':1 }; 
        $scope.cols = [];
        $scope.cacheData = {};

        $scope.loadDevice = function (page){
            $scope.rows = [];
            ajaxData("get_device_list", {'style':1}, function(rst){ 
                var dt = rst.data;
                $scope.data = dt;
                loadTable();
            });    
        }

        function loadTable(){
            $('.table').html("");
            var dt = $scope.data;
            var width = $('.table').width(), maxW = width/4;
            var cols = dt.cols.map(function(d){
                var c = { 'name': d.field, 'title': d.name, style:'max-width:'+ maxW +'px' }; 
                if(d.field in $scope.hideCols)c['visible'] = false;
                return c; 
            });
            cols.push({ 'name': 'removeUser', 'title':'删除人' });
            cols.push({ 'name': 'operate', 'title':'操作' });

            //// 数据呈现
            var rows = []; cout(dt);
            dt.rows.forEach(function(d, i){
                $scope.cacheData[d.id] = i;
                if('companyName' in d)d.companyName = "<a href='companyInfo.html?cp="
                    + escape(d.companyName) + "&pvn="
                    + escape(d.province) + "' title='点击查看详情'>" + d.companyName + "</a>";
                d['operate'] = '<button type="button" class="btn btn-success recover btn-xs" data-id="'
                                + d.id + '">'
                                + '<span class="glyphicon glyphicon-refresh"></span> 恢复'
                                + '</button>';
                d['removeUser'] = '<a href="userInfo.html?u=' + d.removeUser + '" title="点击查看详情">' 
                                + d.removeUser + "</a>";
                if(!(d.field in $scope.hideCols))rows.push(d);
            });

            // 加载表格
            $('.table').footable({
                "paging": { "enabled": true, 'size':8 },
                "filtering": { "enabled": false },
                "sorting": { "enabled": true },
                "columns": cols,
                "rows": rows
            });
            // 操作
            $('.recover').on('click', function(d){
                var id = $(this).attr("data-id");
                ajaxData("recover_device", {'id':id}, function(rst){ 
                    var dt = rst.data;
                    if(dt==0){
                        $scope.data.rows.splice($scope.cacheData[id], 1);
                        loadTable();
                    }
                });  

            });
        }
        
        $scope.loadDevice();
        
    });


</script>

</body>
</html>
